import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import plotly.graph_objects as go
import plotly.express as px
import datetime
from plotly.subplots import make_subplots
import requests
#from bs4 import BeautifulSoup
import seaborn as sns
data = pd.read_csv("D:/kaggle Data/novel-corona-virus-2019-dataset update till jun/covid_19_data.csv")
data.head()
# Percetage of NA Values
NA = [(c, data[c].isna().mean()*100) for c in data]
NA = pd.DataFrame(NA, columns=["Column_name","Percentage"])
NA
data["Province/State"] = data["Province/State"].fillna('unknown')
Change Data type Confirmed, Deaths, Recoverd into int
data[["Confirmed", "Deaths", "Recovered"]] = data[["Confirmed", "Deaths", "Recovered"]].astype(int)
Replacing Mainland China to China
data["Country/Region"] = data["Country/Region"].replace("Mainland China", "China")
data["Current_case"] = data["Confirmed"]- data["Deaths"]-data["Deaths"]
data
Get Last Update
Data = data[data["ObservationDate"] == max(data["ObservationDate"])].reset_index()
COVID-19 in the World Case
data_world = Data.groupby(["ObservationDate"])[["Confirmed", "Current_case","Recovered","Deaths"]].sum().reset_index()
labels = ["Last Update","Confirmed","Current_case","Recovered","Deaths"]
fig = go.Figure(data=[go.Table(header=dict(values=labels),
cells=dict(values=data_world.loc[0,["ObservationDate","Confirmed",
"Current_case","Recovered","Deaths"]]))])
fig.update_layout(
title="Corona Virus in the World"
)
fig.show()
Pie Diagram
labels = ["Current_cases","Recovered","Deaths"]
values = data_world.loc[0, ["Current_case","Recovered","Deaths"]]
fig = px.pie(data_world, values=values, names=labels,color_discrete_sequence=['rgb(77,146,33)',
'rgb(69,144,185)','rgb(77,77,77)'],hole=0.7)
fig.update_layout(
title='Total cases : '+str(data_world["Confirmed"][0]),
)
fig.show()
Evalution of Corona Virus Over Time
data_over_time= data.groupby(["ObservationDate"])[["Confirmed","Current_case","Recovered",
"Deaths"]].sum().reset_index().sort_values("ObservationDate",
ascending =True).reset_index(drop=True)
fig = go.Figure()
fig.add_trace(go.Scatter(x=data_over_time.index, y=data_over_time["Confirmed"],
mode = 'lines',
name = "Confirmed Cases"
))
fig.update_layout(
title = "Evalution of Confirm Case Over Time in the world",
template = 'plotly_white',
yaxis_title="Confirmed cases",
xaxis_title="Days",
)
fig.show()
fig = go.Figure()
fig.add_trace(go.Scatter(x=data_over_time.index, y=data_over_time['Current_case'],
mode='lines', marker_color="black",
name='Current_cases', line=dict(dash="dot")))
fig.update_layout(
title='Evolution of Current cases over time in the world',
template='plotly_white',
yaxis_title = 'Current cases',
xaxis_title = 'Days',
)
fig.show()
fig = go.Figure()
fig.add_trace(go.Scatter(x=data_over_time.index, y=data_over_time['Recovered'],
mode='lines',
name='Recovered', marker_color="green",))
fig.update_layout(
title='Evolution of Recovered cases over time in the world',
template='plotly_white',
yaxis_title = 'Recovered cases',
xaxis_title = 'Days',
)
fig.show()
fig = go.Figure()
fig.add_trace(go.Scatter(x=data_over_time.index, y=data_over_time['Deaths'],
mode='lines', marker_color="red",
name='Deaths', line=dict(dash="dot")))
fig.update_layout(
title='Evolution of Death cases over time in the world',
template='plotly_white',
yaxis_title="Death cases",
xaxis_title="Days",
)
fig.show()
fig = go.Figure(go.Bar(
x = data_over_time["ObservationDate"],
y = data_over_time["Confirmed"],
))
fig.update_layout(
title = "Confirmed Cases in every day",
template = "plotly_dark",
xaxis_title = "Confirmed Cases",
yaxis_title = "Days",
)
fig.show()
fig = go.Figure(go.Bar(
x = data_over_time["ObservationDate"],
y = data_over_time["Current_case"],
marker_color = "rgb(253,187,132)"
))
fig.update_layout(
title = "Current Cases in every day",
template = "plotly_dark",
xaxis_title = "Current Cases",
yaxis_title = "Days",
)
fig.show()
fig = go.Figure(go.Bar(
x = data_over_time["ObservationDate"],
y = data_over_time["Recovered"],
marker_color = "rgb(178,24,42)"
))
fig.update_layout(
title = "Confirmed Cases in every day",
template = "plotly_dark",
xaxis_title = "Recovered Cases",
yaxis_title = "Days",
)
fig.show()
fig = go.Figure(go.Bar(
x = data_over_time["ObservationDate"],
y = data_over_time["Deaths"],
marker_color = "rgb(14,48,101)"
))
fig.update_layout(
title = "Death cases in every day",
template = "plotly_dark",
xaxis_title = "Death Case",
yaxis_title = "Days",
)
fig.show()
Confirmed cases in each country
data_country = data.groupby(["Country/Region"])["Confirmed","Current_case","Recovered",
"Deaths"].sum().reset_index().sort_values("Confirmed",
ascending=False).reset_index(drop=True)
headerColor = 'grey'
rowEvenColor = 'lightgrey'
rowOddColor = 'white'
fig = go.Figure(data=[go.Table(
header=dict(
values=['<b>Country</b>','<b>Confirmed Cases</b>'],
line_color='darkslategray',
fill_color=headerColor,
align=['left','center'],
font=dict(color='white', size=12)
),
cells=dict(
values=[
data_country['Country/Region'],
data_country['Confirmed'],
],
line_color='darkslategray',
fill_color = [[rowOddColor,rowEvenColor,rowOddColor, rowEvenColor,rowOddColor]*len(data_country)],
align = ['left', 'center'],
font = dict(color = 'darkslategray', size = 11)
))
])
fig.update_layout(
title='Confirmed Cases In Each Country',
)
fig.show()
fig = go.Figure(go.Bar(
x = data_country["Confirmed"],
y = data_country["Country/Region"],
orientation="h"
))
fig.update_layout(
title = "Confirmed Cases in Each Country",
template = "plotly_dark",
xaxis_title="Confirmed Cases",
yaxis_title = "Countries",
)
fig.show()
fig = go.Figure(go.Bar(
x = data_country["Recovered"],
y = data_country["Country/Region"],
orientation="h",
marker_color = "#2CA02D",
))
fig.update_layout(
title = "Recovered Cases in Each Country",
template = "plotly_dark",
xaxis_title="Recovered Cases",
yaxis_title = "Countries",
)
fig.show()
fig = go.Figure(go.Bar(
x = data_country["Deaths"],
y = data_country["Country/Region"],
orientation="h",
marker_color = "#DC3956",
))
fig.update_layout(
title = "Deaths Cases in Each Country",
template = "plotly_dark",
xaxis_title="Deaths Cases",
yaxis_title = "Countries",
)
fig.show()
data_per_country = data.groupby(["Country/Region","ObservationDate"])[["Confirmed","Current_case",
"Recovered","Deaths"]].sum().reset_index().sort_values("ObservationDate",
ascending=True).reset_index(drop=True)
fig = px.choropleth(data_per_country, locations=data_per_country['Country/Region'],
color=data_per_country['Confirmed'],locationmode='country names',
hover_name=data_per_country['Country/Region'],
color_continuous_scale=px.colors.sequential.deep,
animation_frame="ObservationDate")
fig.update_layout(
title='Evolution of confirmed cases In Each Country',
)
fig.show()
Top 10 Infected Countries
fig = go.Figure(data=[go.Bar(
x=data_country['Country/Region'][0:10],
y=data_country['Confirmed'][0:10],
text=data_per_country['Confirmed'][0:10],
# textposition='auto',
marker_color='white',
)])
fig.update_layout(
title='Top 10 infected Countries',
xaxis_title="Countries",
yaxis_title="Confirmed Cases",
template='plotly_dark'
)
fig.show()
fig = go.Figure(data=[go.Scatter(
x=data_country['Country/Region'][0:10],
y=data_country['Confirmed'][0:10],
mode='markers',
marker=dict(
color=100+np.random.randn(500),
size=(data_country['Confirmed'][0:10]/1000000),
showscale=True
)
)])
fig.update_layout(
title='Most 10 infected Countries',
xaxis_title="Countries",
yaxis_title="Confirmed Cases",
template='plotly_dark'
)
fig.show()
Recoverd cases in each country
recovered_country = data.groupby(["Country/Region"])["Recovered"].sum().reset_index().sort_values("Recovered",
ascending=False).reset_index(drop=True)
headerColor = 'grey'
rowEvenColor = 'lightgrey'
rowOddColor = 'white'
fig = go.Figure(data=[go.Table(
header=dict(
values=['<b>Country</b>','<b>Recovered Cases</b>'],
line_color='darkslategray',
fill_color=headerColor,
align=['left','center'],
font=dict(color='white', size=12)
),
cells=dict(
values=[
data_country['Country/Region'],
data_country['Recovered'],
],
line_color='darkslategray',
fill_color = [[rowOddColor,rowEvenColor,rowOddColor, rowEvenColor,rowOddColor]*len(data_country)],
align = ['left', 'center'],
font = dict(color = 'darkslategray', size = 11)
))
])
fig.update_layout(
title='Recovered Cases In Each Country',
)
fig.show()
fig = px.pie(recovered_country, values = recovered_country['Recovered'],
names=recovered_country["Country/Region"],
title = "Recovered Cases",
)
fig.update_traces(textposition = "inside",
textinfo = "percent+label")
fig.update_layout(template = "plotly_dark")
fig.show()
fig = go.Figure(data=[go.Bar(
x= recovered_country["Country/Region"][0:10],
y= recovered_country["Recovered"][0:10],
textposition = "auto",
marker_color = "lightgreen",
)])
fig.update_layout(
title = "Top 10 Infected Country",
xaxis_title = "Countries",
yaxis_title = "Recovered Cases",
template= "plotly_dark"
)
fig.show()
Deaths cases in each country
headerColor = 'grey'
rowEvenColor = 'lightgrey'
rowOddColor = 'white'
fig = go.Figure(data=[go.Table(
header=dict(
values=['<b>Country</b>','<b>Deaths </b>'],
line_color='darkslategray',
fill_color=headerColor,
align=['left','center'],
font=dict(color='white', size=12)
),
cells=dict(
values=[
data_country['Country/Region'],
data_country["Deaths"],
],
line_color='darkslategray',
fill_color = [[rowOddColor,rowEvenColor,rowOddColor, rowEvenColor,rowOddColor]*len(data_country)],
align = ['left', 'center'],
font = dict(color = 'darkslategray', size = 11)
))
])
fig.update_layout(
title='Deaths Cases In Each Country',
)
fig.show()
fig = go.Figure(data=[go.Bar(
x= recovered_country["Country/Region"][0:10],
y= recovered_country["Deaths"][0:10],
textposition = "auto",
marker_color = "red",
)])
fig.update_layout(
title = "Top 10 Infected Country",
xaxis_title = "Countries",
yaxis_title = "Dea Cases",
template= "plotly_dark"
)
fig.show()
Corona Virus in my India
data_india = data[(data["Country/Region"] == "India")].reset_index(drop=True)
data_india
fig = go.Figure()
fig.add_trace(go.Scatter(
x = data_india["ObservationDate"],
y = data_india["Confirmed"],
mode = "lines",
name = "Confirmed Cases"
))
fig.add_trace(go.Scatter(
x = data_india["ObservationDate"],
y = data_india["Current_case"],
mode = "lines",
name = "Confirmed Cases", line = dict(dash="dot")
))
fig.add_trace(go.Scatter(
x = data_india["ObservationDate"],
y = data_india["Recovered"],
mode = "lines",
name = "Recovered Cases", marker_color="green"
))
fig.add_trace(go.Scatter(
x = data_india["ObservationDate"],
y = data_india["Deaths"],
mode = "lines",
name = "Death Cases", line = dict(dash="dot"), marker_color= "black"
))
fig.update_layout(
title = "Evalution cases over time in India",
template = "plotly_white"
)
fig.show()
fig = go.Figure(go.Bar(
x=data_india['ObservationDate'],
y=data_india['Confirmed'],
marker_color='rgb(13,48,100)'
))
fig.update_layout(
title='Confirmed cases In Each Day',
template='plotly_dark',
xaxis_title="Confirmed cases",
yaxis_title="Days",
)
fig.show()
fig = go.Figure(go.Bar(
x=data_india['ObservationDate'],
y=data_india['Current_case'],
marker_color='rgb(13,48,70)'
))
fig.update_layout(
title='Current cases In Each Day',
template='plotly_dark',
xaxis_title="Current cases",
yaxis_title="Days",
)
fig.show()
fig = go.Figure(go.Bar(
x=data_india['ObservationDate'],
y=data_india['Recovered'],
marker_color='rgb(11,48,100)'
))
fig.update_layout(
title='Recovered cases In Each Day',
template='plotly_dark',
xaxis_title="Recovered cases",
yaxis_title="Days",
)
fig.show()
fig = go.Figure(go.Bar(
x=data_india['ObservationDate'],
y=data_india['Deaths'],
marker_color='rgb(13,48,100)'
))
fig.update_layout(
title='Deaths cases In Each Day',
template='plotly_dark',
xaxis_title="Deaths cases",
yaxis_title="Days",
)
fig.show()
data_india_latest=data_india[data_india["ObservationDate"] == max(data_india["ObservationDate"])].reset_index()
data_india_latest
data_india_state = data_india_latest.groupby(["Province/State"])["Confirmed","Current_case","Recovered","Deaths"].sum().reset_index().sort_values("Confirmed", ascending=False).reset_index(drop=True)
fig = px.pie(data_india_state, values= data_india_state["Confirmed"],
names=data_india_state["Province/State"],
title="Confirmed Cases in India", hole=.2)
fig.update_traces(
textposition="inside", textinfo = "percent+label"
)
fig.show()